{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 数据类型\n",
    "\n",
    "* 整数\n",
    "\n",
    "正、负整数：0, 100, -1000 等等\n",
    "\n",
    "十六进制以0x前缀，0-9，a-f：0xff00, 0x270d等等\n",
    "\n",
    "注意：Python的整数没有大小限制，而某些语言的整数根据其存储长度是有大小限制的，例如Java对32位整数的范围限制在-2147483648-2147483647。\n",
    "   \n",
    "* 浮点数\n",
    "\n",
    "小数：1.2, 3.14, 0.007, -2.8\n",
    "\n",
    "科学计数法：1.2e5, 3.14e-8\n",
    "\n",
    "Python的浮点数也没有大小限制，但是超出一定范围就直接表示为inf（无限大）。\n",
    "\n",
    "* 字符型\n",
    "\n",
    "以单引号`'`或双引号`\"`括起来的任意字符。`''`或`\"\"`本身只是一种表示方式，不是字符串的一部分，因此，字符串'abc'只有a，b，c这3个字符。如果'本身也是一个字符，那就可以用\"\"括起来，比如\"I'm OK\"包含的字符是I，'，m，空格，O，K这6个字符。\n",
    "\n",
    "如果字符串内部既包含`'`又包含`\"`怎么办？可以用转义字符\\来标识，比如：\n",
    "\n",
    "`'I\\'m \\\"OK\\\"!'`\n",
    "\n",
    "表示的字符串内容是：\n",
    "\n",
    "`I'm \"OK\"!`\n",
    "\n",
    "转义字符\\可以转义很多字符，比如`\\n`表示换行，`\\t`表示制表符，字符`\\`本身也要转义，所以`\\\\`表示的字符就是`\\`，可以在Python的交互式命令行用print()打印字符串看看："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I'm ok.\n"
     ]
    }
   ],
   "source": [
    "print('I\\'m ok.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I'm learning\n",
      "Python.\n"
     ]
    }
   ],
   "source": [
    "print('I\\'m learning\\nPython.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\\\n",
      "\\\n"
     ]
    }
   ],
   "source": [
    "print('\\\\\\n\\\\')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "如果字符串里面有很多字符都需要转义，就需要加很多`\\`，为了简化，Python还允许用`r''`表示`''`内部的字符串默认不转义，可以自己试试："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\\\t\\\n"
     ]
    }
   ],
   "source": [
    "print('\\\\\\t\\\\')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\\\\\\t\\\\\n"
     ]
    }
   ],
   "source": [
    "print(r'\\\\\\t\\\\')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "如果字符串内部有很多换行，用\\n写在一行里不好阅读，为了简化，Python允许用'''...'''的格式表示多行内容，可以自己试试："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "line1\n",
      "line2\n",
      "line3\n"
     ]
    }
   ],
   "source": [
    "print('''line1\n",
    "... line2\n",
    "... line3''')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "上面是在交互式命令行内输入，注意在输入多行内容时，提示符由`>>>`变为`...`，提示你可以接着上一行输入，注意`...`是提示符，不是代码的一部分："
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "当输入完结束符`'''`和括号`)`后，执行该语句并打印结果。\n",
    "\n",
    "如果写成程序并存为.py文件，就是："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "line1\n",
      "line2\n",
      "line3\n"
     ]
    }
   ],
   "source": [
    "print('''line1\n",
    "line2\n",
    "line3''')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "多行字符串`'''...'''`还可以在前面加上r使用，请自行测试："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello,\\n\n",
      "world\n"
     ]
    }
   ],
   "source": [
    "print(r'''hello,\\n\n",
    "world''')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 布尔值\n",
    "\n",
    "布尔值和布尔代数的表示完全一致，一个布尔值只有`True`、`False`两种值，要么是True，要么是False，在Python中，可以直接用`True`、`False`表示布尔值（请注意大小写），也可以通过布尔运算计算出来：\n",
    "\n",
    "布尔值可以用and、or和not运算。\n",
    "\n",
    "and运算是与运算，只有所有都为True，and运算结果才是True：\n",
    "or运算是或运算，只要其中有一个为True，or运算结果就是True：\n",
    "not运算是非运算，它是一个单目运算符，把True变成False，False变成True："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "3 > 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "True and False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "True or False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "not True"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 空值\n",
    "\n",
    "空值是Python里一个特殊的值，用None表示。None不能理解为0，因为0是有意义的，而None是一个特殊的空值。"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
